﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <title>设置报表查询条件</title>

    <link href="../../Scripts/bootstrap/css/bootstrap.css" rel="Stylesheet" />
    <link href="../../Scripts/bootstrap/css/font-awesome.css" rel="Stylesheet" />
    <link rel="stylesheet" href="../../Scripts/bootstrap/css/css.css" type="text/css" media="all" />
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>

    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>



    <script language="javascript" type="text/javascript">

        var rptNo = GetQueryString("RptNo");
        var flowNo = GetQueryString("FK_Flow");

        //页面启动函数.
        $(function () {

            $("#Msg").html("<img src=../../../Img/loading.gif />&nbsp;正在加载,请稍后......");

            rptNo = GetQueryString("RptNo");
            if (rptNo == null)
                rptNo = "";

            InitPage();

            $("#Msg").html("");

        });

        function InitPage() {

            if (rptNo.indexOf("RptMyDept") == -1)
                $("#LevelDiv").hide();

            var checkBoxIDs = GetSelectedCheckIDs();
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_RptDfine");
            handler.AddPara("RptNo", rptNo);
            handler.AddPara("FK_Flow", flowNo);
            var data = handler.DoMethodReturnString("S5SearchCond_Init");

            if (data.indexOf("@") == 0) {
                alert(data);
                return;
            }
            var jsData = JSON.parse(data);

            var md = jsData["Main"][0]; //主表数据.
            md = new Entity("BP.Sys.MapData", md);

            var Sys_MapAttr = jsData["Sys_MapAttr"]; //所有的列.
            var Sys_MapAttrOfDate = jsData["Sys_MapAttrOfDate"]; //日期列表.
            //关键字查询.
            var isSearchKey = md.GetPara("RptIsSearchKey") == "1" ? true : false;
            document.getElementById("CB_Key_0").checked = isSearchKey;

            document.getElementById("CB_Key_1").checked = isSearchKey == true ? false : true;

            document.getElementById("CB_NextLeavel").checked = (md.AtPara.indexOf("@IsSearchNextLeavel=1@") != -1);

            var RptStringSearchKeys = md.GetPara("RptStringSearchKeys");
            var RptSearchKeys = md.GetPara("RptSearchKeys");
            var RptDTSearchWay = md.GetPara("RptDTSearchWay");
            var RptDTSearchKey = md.GetPara("RptDTSearchKey");

            //绑定外键字段.
            var count = 0;
            var disabled = "";
            if (isSearchKey == true)
                disabled = " disabled=disabled ";
            for (var i = 0, length = Sys_MapAttr.length; i < length; i++) {
                var attr = Sys_MapAttr[i], flag = false;
                //文本字段
                if (attr.MyDataType == 1 && attr.UIContralType == 0) {
                    count++;
                    flag = false;
                    if (RptStringSearchKeys) {
                        flag = (RptStringSearchKeys.indexOf("*" + attr.KeyOfEn + ",") != -1);
                    }
                    $("#StringKeys").append("<input type='checkbox' " + disabled + (flag ? " checked = 'checked'" : "") + " id='" + attr.KeyOfEn + "'  data-name='" + attr.Name + "'/><label for='" + attr.KeyOfEn + "' >" + attr.Name + "(" + attr.KeyOfEn + ")</label><br/>");
                    continue;
                }

                if (attr.UIContralType == 1 || attr.UIContralType == 3) {
                } else
                    continue;

                flag == false;
                if (RptSearchKeys) {
                    flag = (RptSearchKeys.indexOf("*" + attr.KeyOfEn + "*") != -1);
                }
                $("#FKeys").append("<input type='checkbox' " + (flag ? "checked = 'checked'" : "") + " id='" + attr.KeyOfEn + "' /><label for='" + attr.KeyOfEn + "' >" + attr.Name + "(" + attr.KeyOfEn + ")</label></br>");
            }

            $("#DDL_DTSearchWay").val(RptDTSearchWay);

            //绑定日期下拉框.
            if (Sys_MapAttrOfDate != null) {
                GenerBindDDL("DDL_DTSearchKey", Sys_MapAttrOfDate, "KeyOfEn", "Name", RptDTSearchKey);
            }

            return;
        }

        function Save() {

            var FK_Flow = QueryString("FK_Flow"),
                RptNo = QueryString("RptNo"),
                IsSearchKey = document.getElementById("CB_Key_0").checked ? 1 : 0,
                DTSearchWay = document.getElementById("DDL_DTSearchWay").value,
                DTSearchKey = document.getElementById("DDL_DTSearchKey").value,
                Fields = "";

            //获得外键.
            var oChecks = document.getElementById("FKeys").getElementsByTagName("input");
            for (var i = 0, len = oChecks.length; i < len; i++) {
                var item = oChecks[i];
                if (item.checked) {
                    Fields += "*" + item.id;
                }
            }

            //alert(Fields);

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_RptDfine");
            handler.AddPara("RptNo", rptNo);
            handler.AddPara("FK_Flow", flowNo);

            handler.AddPara("Fields", Fields);
            handler.AddPara("IsSearchKey", IsSearchKey); //是否按照关键字查询?

            handler.AddPara("DTSearchWay", DTSearchWay); //日期查询方式?
            handler.AddPara("DTSearchKey", DTSearchKey); //日期字段

            handler.AddPara("IsSearchNextLeavel", document.getElementById("CB_NextLeavel").checked ? 1 : 0);

            fields = "";
            if (document.getElementById("CB_Key_1").checked == 1) {
                oChecks = document.getElementById("StringKeys").getElementsByTagName("input");
                for (var i = 0, len = oChecks.length; i < len; i++) {
                    var item = oChecks[i];
                    if (item.checked) {
                        fields += "*" + item.id + "," + item.getAttribute("data-name");
                    }
                }
                if (fields != "")
                    fields = fields + "*";
            }

            handler.AddPara("RptStringSearchKeys", fields);

            var data = handler.DoMethodReturnString("S5SearchCond_Save");

            window.location.href = window.location.href;
            //alert(data);
        }


        //获得所有的checkbox 的id组成一个string用逗号分开, 以方便后台接受的值保存.
        function GetSelectedCheckIDs() {

            var checkBoxIDs = "";
            var arrObj = document.getElementsByTagName("input");

            for (var i = 0, len = arrObj.length; i < len; i++) {

                if (arrObj[i].type == 'checkbox') {
                    if (arrObj[i].checked)
                        checkBoxIDs += arrObj[i].id + ',';
                }
            }
            return checkBoxIDs;
        }

        function changeStringKeysState(val) {
            if (val == 0) {
                $("#StringKeys input[type=checkbox]").attr("disabled", 'disabled');
                $("#StringKeys input[type=checkbox]").removeAttr("checked");
            }
            if (val == 1) {
                $("#StringKeys input[type=checkbox]").removeAttr("disabled");
            }
        }

    </script>
    <base target="_self" />
</head>
<body class="easyui-layout">

    <form id="cc">

        <fieldset>
            <legend>关键字查询（字段String类型查询） </legend>

            <label for="CB_Key_0"><input type="radio" name="CB_Key" id="CB_Key_0" value="0" onchange="changeStringKeysState(this.value)" />启用关键字查询</label><span style="margin-left:10px">说明：关键字查询是接受用户输入一个关键字，在整个报表的显示列中使用like查询(外键、枚举、数值类型的除外))</span><br />
            <label for="CB_Key_1"><input type="radio" name="CB_Key" id="CB_Key_1" value="1" onchange="changeStringKeysState(this.value)" />启用特定字段的查询</label><span style="margin-left:10px">说明：选择特定字段，在报表中根据like模糊查询</span><br />
            <div id="StringKeys" style="margin-left:15px"> </div>

            <legend>外键与枚举类型（显示在下拉框里）</legend>
            <div id="FKeys"></div>

            <legend>时间段（仅支持一个时间段）</legend>
            对数据按照时间段进行查询，比如：按流程的发起时间，在指定时间段内进行查询。<br />
            选择方式：<select name="DDL_DTSearchWay" id="DDL_DTSearchWay">
                <option selected="selected" value="0">不启用</option>
                <option value="1">按日期</option>
                <option value="2">按日期时间</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;字段：<select name="DDL_DTSearchKey"
                                                                    id="DDL_DTSearchKey">
                <!--<option value="FlowEnderRDT">FlowEnderRDT 结束时间</option>
                <option selected="selected" value="FlowStartRDT">FlowStartRDT 发起时间</option>-->
            </select>
        </fieldset>

        <div style='width: 100%' id="LevelDiv">
            <div class='easyui-panel' title='是否查询子级部门' data-options="iconCls:'icon-tip',fit:true"
                 style='height: auto; padding: 10px'>
                子级部门查询是查询这个子级部门的下一级<br />
                <input id="CB_NextLeavel" type="checkbox" name="CB_NextLeavel" /><label for="CB_NextLeavel">是否查询子级部门</label>
            </div>
        </div>

        <button id="Btn_Save" onclick="Save()">保存 </button>
    </form>


</body>
</html>
